import java.util.Scanner;

class Repo {

	private int count;
	private String[] str;
	private boolean num = false; 
	public Repo(String items) {
		str = items.split(" ");
	}

	public synchronized int getSize() {
		return str.length - count;
	}
	
	public synchronized void zero() {
		while (getSize() > 0) {
			while (num) {
				try {
					wait();
				} catch (Exception e) {
				}
			}
			if (getSize() > 0) {
				System.out.println(Thread.currentThread().getName() + " finish " + str[count]);
				count++;
				num = true;
				notify();
			}			
		}
	}	
	public synchronized void one() {
		while (getSize() > 0) {
			while (!num) {
				try {
					wait();
				} catch (Exception e) {
				}
			}
			if (getSize() > 0) {
				System.out.println(Thread.currentThread().getName() + " finish " + str[count]);
				count++;
				num = false;
				notify();
			}
			
		}
	}
	

}

class Worker1 implements Runnable{
	private Repo repo;
	public Worker1(Repo repo) {
		this.repo = repo;
	}
	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (repo.getSize() != 0) {
		repo.zero();
		}
	}
	
}

class Worker2 implements Runnable {
	private Repo repo;
	public Worker2(Repo repo) {
		this.repo = repo;
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (repo.getSize() != 0) {
			repo.one();	
		}
	}
}



public class Main {
    public static void main(String[] args) throws InterruptedException {
        Scanner sc = new Scanner(System.in);
        Repo repo = new Repo(sc.nextLine());
        Thread t1 = new Thread(new Worker1(repo));
        Thread t2 = new Thread(new Worker2(repo));
        t1.start();
        Thread.yield();
        t2.start();
        sc.close();
    }
}